home *** CD-ROM | disk | FTP | other *** search
/ EuroCD 3 / EuroCD 3.iso / Programming / RTGMaster / includes / sasc / rtgmaster / rtgTCPIP.h < prev   
Encoding:
C/C++ Source or Header  |  1998-06-24  |  7.2 KB  |  257 lines

  1. //     $VER: rtgsublibs.i 1.007 (15 Jan 1998)
  2.  
  3. #ifndef RTGMASTER_RTGTCPIP_H
  4. #define RTGMASTER_RTGTCPIP_H 1
  5.  
  6. #ifndef LARGE_BUFSIZE
  7. #define LARGE_BUFSIZE (12 * 1024)
  8. #endif
  9.  
  10. #ifndef GARBAGE_SPACE
  11. #define GARBAGE_SPACE 32
  12. #endif
  13.  
  14. #ifndef  NBBY
  15. #define NBBY    8                       /* number of bits in a byte */
  16. #endif
  17.  
  18. #ifndef FD_SETSIZE
  19. #define FD_SETSIZE      64
  20. #endif
  21.  
  22. #ifndef INVALID_SOCKET
  23. #define INVALID_SOCKET -1
  24. #endif
  25.  
  26. #ifndef SYS_TYPES_H
  27. #ifndef fd_mask
  28. typedef long    fd_mask;
  29. #endif
  30. #endif
  31.  
  32. #ifndef NFDBITS
  33. #define NFDBITS (sizeof(fd_mask) * NBBY) /* bits per mask */
  34. #endif
  35.  
  36. #ifndef howmany
  37. #define howmany(x, y)   (((x)+((y)-1))/(y))
  38. #endif
  39.  
  40. #ifndef SYS_TYPES_H
  41. typedef struct fd_set {
  42.         fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)];
  43. } fd_set;
  44.  
  45. typedef unsigned char   u_char;
  46. typedef unsigned short  u_short;
  47. typedef unsigned int    u_int;
  48. typedef unsigned long   u_long;
  49. typedef unsigned short  ushort;         /* Sys V compatibility */
  50. typedef char*           caddr_t;        /* core address */
  51. typedef unsigned long   dev_t;
  52. typedef unsigned long   ino_t;
  53. typedef long            off_t;
  54.  
  55. #define SYS_TYPES_H
  56.  
  57. // Sort of a hack (why i did this : See below...)
  58. // (Sys/types.h differs, according to, if we have
  59. // only SAS/C installed or SAS/C + AmiTCP includes.
  60. // This code should not give an error, anyways, which
  61. // version of sys/types.h we have installed. So i did
  62. // all sys/types.h stuff from SAS/C + AmiTCP HERE and
  63. // hindered sys/types.h to be included :) ...
  64.  
  65.  
  66. #endif
  67.  
  68. #ifndef FD_SET
  69. #define FD_SET(n, p)    ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
  70. #endif
  71.  
  72. #ifndef FD_CLR
  73. #define FD_CLR(n, p)    ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
  74. #endif
  75.  
  76. #ifndef FD_ISSET
  77. #define FD_ISSET(n, p)  ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
  78. #endif
  79.  
  80. #ifndef FD_ZERO
  81. #define FD_ZERO(p)      bzero((char *)(p), sizeof(*(p)))
  82. #endif
  83.  
  84. #ifndef SOCK_STREAM
  85. #define SOCK_STREAM     1               /* stream socket */
  86. #endif
  87.  
  88. #ifndef SOCK_DGRAM
  89. #define SOCK_DGRAM      2               /* datagram socket */
  90. #endif
  91.  
  92. struct RTG_Buff
  93. {
  94.  char sock[12][1024];
  95.  int num[12];
  96.  int in_size;
  97.  int out_size;
  98. };
  99.  
  100. // Sort of a HACK that we do not get a collision
  101. // with AmiTCP includes, if installed... :)
  102. // (most of the stuff in this includefile is
  103. // only needed to COMPILE rtgmaster.library itself,
  104. // not for the USAGE of the library, so do not wonder,
  105. // if it is missing in the ASM part... the TCP/IP
  106. // part of rtgmaster is written in C, contrary to
  107. // the rest of rtgmaster (which is written in ASM)
  108.  
  109. #ifndef NET_IN_H
  110. #define NET_IN_H
  111.  
  112. #define IN_H XXX - compatibility
  113.  
  114. /*
  115.  * Macros for network/external number representation conversion.
  116.  */
  117. #ifndef ntohl
  118. #define ntohl(x)        (x)
  119. #define ntohs(x)        (x)
  120. #define htonl(x)        (x)
  121. #define htons(x)        (x)
  122.  
  123. #define NTOHL(x)        (x)
  124. #define NTOHS(x)        (x)
  125. #define HTONL(x)        (x)
  126. #define HTONS(x)        (x)
  127. #endif
  128.  
  129. /*
  130.  * Constants and structures defined by the internet system,
  131.  * Per RFC 790, September 1981.
  132.  */
  133.  
  134. /*
  135.  * Protocols
  136.  */
  137. #define IPPROTO_IP              0               /* dummy for IP */
  138. #define IPPROTO_ICMP            1               /* control message protocol */
  139. #define IPPROTO_GGP             3               /* gateway^2 (deprecated) */
  140. #define IPPROTO_TCP             6               /* tcp */
  141. #define IPPROTO_EGP             8               /* exterior gateway protocol */
  142. #define IPPROTO_PUP             12              /* pup */
  143. #define IPPROTO_UDP             17              /* user datagram protocol */
  144. #define IPPROTO_IDP             22              /* xns idp */
  145. #define IPPROTO_TP              29              /* tp-4 w/ class negotiation */
  146. #define IPPROTO_EON             80              /* ISO cnlp */
  147.  
  148. #define IPPROTO_RAW             255             /* raw IP packet */
  149. #define IPPROTO_MAX             256
  150.  
  151.  
  152. /*
  153.  * Local port number conventions:
  154.  * Ports < IPPORT_RESERVED are reserved for
  155.  * privileged processes (e.g. root).
  156.  * Ports > IPPORT_USERRESERVED are reserved
  157.  * for servers, not necessarily privileged.
  158.  */
  159. #define IPPORT_RESERVED         1024
  160. #define IPPORT_USERRESERVED     5000
  161.  
  162. /*
  163.  * Internet address (a structure for historical reasons)
  164.  */
  165. struct in_addr {
  166.         u_long s_addr;
  167. };
  168.  
  169. /*
  170.  * Definitions of bits in internet address integers.
  171.  * On subnets, the decomposition of addresses to host and net parts
  172.  * is done according to subnet mask, not the masks here.
  173.  */
  174. #define IN_CLASSA(i)            (((long)(i) & 0x80000000) == 0)
  175. #define IN_CLASSA_NET           0xff000000
  176. #define IN_CLASSA_NSHIFT        24
  177. #define IN_CLASSA_HOST          0x00ffffff
  178. #define IN_CLASSA_MAX           128
  179.  
  180. #define IN_CLASSB(i)            (((long)(i) & 0xc0000000) == 0x80000000)
  181. #define IN_CLASSB_NET           0xffff0000
  182. #define IN_CLASSB_NSHIFT        16
  183. #define IN_CLASSB_HOST          0x0000ffff
  184. #define IN_CLASSB_MAX           65536
  185.  
  186. #define IN_CLASSC(i)            (((long)(i) & 0xe0000000) == 0xc0000000)
  187. #define IN_CLASSC_NET           0xffffff00
  188. #define IN_CLASSC_NSHIFT        8
  189. #define IN_CLASSC_HOST          0x000000ff
  190.  
  191. #define IN_CLASSD(i)            (((long)(i) & 0xf0000000) == 0xe0000000)
  192. #define IN_MULTICAST(i)         IN_CLASSD(i)
  193.  
  194. #define IN_EXPERIMENTAL(i)      (((long)(i) & 0xe0000000) == 0xe0000000)
  195. #define IN_BADCLASS(i)          (((long)(i) & 0xf0000000) == 0xf0000000)
  196.  
  197. #define INADDR_ANY              (u_long)0x00000000
  198. #define INADDR_BROADCAST        (u_long)0xffffffff      /* must be masked */
  199. #if !defined(KERNEL) || defined(AMITCP)
  200. #define INADDR_NONE             0xffffffff              /* -1 return */
  201. #endif
  202.  
  203. #define IN_LOOPBACKNET          127                     /* official! */
  204.  
  205. /*
  206.  * Socket address, internet style.
  207.  */
  208. struct sockaddr_in {
  209.         u_char  sin_len;
  210.         u_char  sin_family;
  211.         u_short sin_port;
  212.         struct  in_addr sin_addr;
  213.         char    sin_zero[8];
  214. };
  215.  
  216. /*
  217.  * Structure used to describe IP options.
  218.  * Used to store options internally, to pass them to a process,
  219.  * or to restore options retrieved earlier.
  220.  * The ip_dst is used for the first-hop gateway when using a source route
  221.  * (this gets put into the header proper).
  222.  */
  223. struct ip_opts {
  224.         struct  in_addr ip_dst;         /* first hop, 0 w/o src rt */
  225.         char    ip_opts[40];            /* actually variable in size */
  226. };
  227.  
  228. /*
  229.  * Options for use with [gs]etsockopt at the IP level.
  230.  * First word of comment is data type; bool is stored in int.
  231.  */
  232. #define IP_OPTIONS      1       /* buf/ip_opts; set/get IP per-packet options */
  233. #define IP_HDRINCL      2       /* int; header is included with data (raw) */
  234. #define IP_TOS          3       /* int; IP type of service and precedence */
  235. #define IP_TTL          4       /* int; IP time to live */
  236. #define IP_RECVOPTS     5       /* bool; receive all IP options w/datagram */
  237. #define IP_RECVRETOPTS  6       /* bool; receive IP options for response */
  238. #define IP_RECVDSTADDR  7       /* bool; receive IP dst addr w/datagram */
  239. #define IP_RETOPTS      8       /* ip_opts; set/get IP per-packet options */
  240.  
  241. #endif /* !IN_H */
  242.  
  243.  
  244. struct RTG_Socket
  245. {
  246.     int s;   // The TCP/IP Socket
  247.     int num; // number of open connections,
  248.              // including the server itself
  249.     struct RTG_Socket *list; // List of connections of a server
  250.     fd_set input_set, output_set, exc_set; // The sets
  251.     struct sockaddr_in peer;
  252.     int mode;
  253.     int server;
  254. };
  255.  
  256. #endif
  257.